package demo7;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Person implements InitializingBean, DisposableBean {
    private String name;
    private int age;


    public Person(){
        System.out.println("1:Person()的构造器执行了");
    }

    @Value("张三")
    public void setName(String name){
        System.out.print("2:setName()方法执行了,");
        this.name = name;
        System.out.println("初始化name完毕");
    }

    @Value("18")
    public void setAge(int age){
        System.out.print("3:setAge()方法执行了,");
        this.age = age;
        System.out.println("初始化age完毕");
    }


    public void play(){
        System.out.println("出去玩");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.print("4:afterPropertiesSet()方法执行了,");
        System.out.println("初始化完毕");
    }
    @Override
    public void destroy() throws Exception {
        System.out.print("5：容器即将销毁，通知Person,调用destroy方法");
    }



}
